Data Types


JavaScript provides various data types to hold different kinds of values. These data types can be categorized into primitive and non-primitive types, each serving unique purposes in coding.

1. Primitive Data Types

Primitive data types are the most basic data types in JavaScript. They include:

let num = 42; // Number
    let str = "Hello, World!"; // String
    let bool = true; // Boolean
    let undef; // Undefined
    let nul = null; // Null
    let sym = Symbol("unique"); // Symbol
    let bigInt = 9007199254740991n; // BigInt

2. Non-Primitive Data Types

Non-primitive data types are objects and can hold collections of values and more complex entities. They include:

let obj = { name: "John", age: 30 }; // Object
    let arr = [1, 2, 3, 4, 5]; // Array
    function greet() { console.log("Hello!"); } // Function
    let date = new Date(); // Date
    let map = new Map(); // Map
    let set = new Set(); // Set
    let weakMap = new WeakMap(); // WeakMap
    let weakSet = new WeakSet(); // WeakSet